// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Tube Switch Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 55 : TYPE_TUBESWITCH


// Static Values

// Tables

event ObjectMain
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		if object[currentPlayer].value34 == 1
			object[currentPlayer].value34 = 0
		end if
		CheckEqual(object[currentPlayer].state, PlayerObject_Death)
		temp0 = checkResult
		CheckEqual(object[currentPlayer].state, PlayerObject_KnuxLedgePullUp)
		temp0 |= checkResult
		CheckEqual(object[currentPlayer].state, PlayerObject_KnuxWallClimb)
		temp0 |= checkResult
		if temp0 == 0
			BoxCollisionTest(C_TOUCH, object.entityPos, -16, -16, 16, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				if object[currentPlayer].yvel < 0
					object[currentPlayer].yvel = 0
				end if
				switch object.propertyValue
				case 0
					if object[currentPlayer].xvel > 0
						if object[currentPlayer].animation != ANI_JUMPING
							if object[currentPlayer].state != PlayerObject_HandleRollDecel
								PlaySfx(SfxName[Rolling], 0)
							end if
						end if
						if object[currentPlayer].state == PlayerObject_KnuxGlideLeft
							FlipSign(object[currentPlayer].speed)
						end if
						object[currentPlayer].direction = FLIP_NONE
						object[currentPlayer].state = PlayerObject_HandleRollDecel
						object[currentPlayer].animation = ANI_JUMPING
					else
						if object[currentPlayer].gravity == GRAVITY_GROUND
							if object[currentPlayer].xvel > -0x20000
								object[currentPlayer].speed = -0x20000
							end if
						end if
						object[currentPlayer].state = PlayerObject_HandleRolling
						object[currentPlayer].animation = ANI_JUMPING
					end if
					break
				case 1
					if object[currentPlayer].xvel < 0
						if object[currentPlayer].animation != ANI_JUMPING
							if object[currentPlayer].state != PlayerObject_HandleRollDecel
								PlaySfx(SfxName[Rolling], 0)
							end if
						end if
						if object[currentPlayer].state == PlayerObject_KnuxGlideLeft
							FlipSign(object[currentPlayer].speed)
						end if
						object[currentPlayer].direction = FLIP_X
						object[currentPlayer].state = PlayerObject_HandleRollDecel
						object[currentPlayer].animation = ANI_JUMPING
					else
						if object[currentPlayer].gravity == GRAVITY_GROUND
							if object[currentPlayer].xvel < 0x20000
								object[currentPlayer].speed = 0x20000
							end if
						end if
						object[currentPlayer].state = PlayerObject_HandleRolling
						object[currentPlayer].animation = ANI_JUMPING
					end if
					break
				end switch
				object.value0 = 1
			else
				object.value0 = 0
			end if
		end if
	next
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
